

package explorandum.g2;

import java.awt.Color;
import java.awt.Point;
import java.util.ArrayList;
import java.util.Random;

import explorandum.Logger;
import explorandum.Move;
import explorandum.Player;
import explorandum.g2.*;

public class Team2 implements Player
{
	Logger log;
	Random rand;
	public int n,p,d,myID;
	
	ArrayList<Point> stepped=new ArrayList<Point>();

	public void register(int explorerID, int rounds, int explorers, int range, Logger _log, Random _rand)
	{
		// TODO Auto-generated method stub
		log = _log;
		rand = _rand;
		n=rounds;
		p=explorers;
		d=range;
		myID=explorerID;
	}

	public Color color() throws Exception
	{
		return Color.GREEN;
	}

	//Picks a random adjacent cell that is not blocked
	//(Always picks a valid move)
	public Move move(Point currentLocation, Point[] offsets, Boolean[] hasExplorer, Integer[][] otherExplorers, Integer[] terrain, int time) throws Exception
	{

		//To build a list of valid locations
		ArrayList<Integer> valid = new ArrayList<Integer>();
        stepped.add(currentLocation);
		//Loop through adjacent cells
		
        for (int i = 0; i < _dx.length; i++)
			if (_dx[i] != 0 || _dy[i] != 0)
			{
				//Find this cell in visible cells list
				for (int j = 0; j < offsets.length; j++)
				{
					Point point = offsets[j];
					
					//if adjacent cell and LAND
					if (point.x == currentLocation.x + _dx[i] && point.y == currentLocation.y + _dy[i] && terrain[j] == LAND )
					{
						//add to valid actions list
						//(i is the index of the action needed to move to this cell)
						valid.add(i);
						break;
					}
				}
			}

		// if no valid location, stay put
		if (valid.size() == 0)
			return new Move(STAYPUT);
		
Move m2=StepLike.getMove(currentLocation,offsets, hasExplorer, otherExplorers,terrain,time,n,p,d,myID,stepped,_dx,_dy,rand);
		//pick a random value from valid actions
		//return new Move(valid.get(rand.nextInt(valid.size())));
	return m2;
	}

	public String name() throws Exception
	{
		return "Team2";
	}
}
